/*
Copyright (C) 2018-2019 de4dot@gmail.com

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#if NASM
using System;
using Iced.Intel.FormatterInternal;

namespace Iced.Intel.NasmFormatterInternal {
	static class MemorySizes {
		public readonly struct Info {
			public readonly FormatterString keyword;
			public readonly FormatterString bcstTo;
			public Info(FormatterString keyword, FormatterString bcstTo) {
				this.keyword = keyword;
				this.bcstTo = bcstTo;
			}
		}
		public static readonly Info[] AllMemorySizes = GetMemorySizes();
		enum MemoryKeywords : byte {
			None,
			@byte,
			dword,
			far,
			fpuenv14,
			fpuenv28,
			fpustate108,
			fpustate94,
			oword,
			qword,
			tword,
			word,
			yword,
			zword,
		}
		enum BroadcastToKind {
			b1to2,
			b1to4,
			b1to8,
			b1to16,
		}
		static Info[] GetMemorySizes() {
#if HAS_SPAN
			ReadOnlySpan<byte>
#else
			byte[]
#endif
			bcstToData = new byte[IcedConstants.NumberOfMemorySizes - (int)IcedConstants.FirstBroadcastMemorySize] {
				// GENERATOR-BEGIN: BcstTo
				// ⚠️This was generated by GENERATOR!🦹‍♂️
				(byte)BroadcastToKind.b1to2,
				(byte)BroadcastToKind.b1to2,
				(byte)BroadcastToKind.b1to2,
				(byte)BroadcastToKind.b1to4,
				(byte)BroadcastToKind.b1to4,
				(byte)BroadcastToKind.b1to2,
				(byte)BroadcastToKind.b1to2,
				(byte)BroadcastToKind.b1to2,
				(byte)BroadcastToKind.b1to4,
				(byte)BroadcastToKind.b1to2,
				(byte)BroadcastToKind.b1to8,
				(byte)BroadcastToKind.b1to8,
				(byte)BroadcastToKind.b1to4,
				(byte)BroadcastToKind.b1to4,
				(byte)BroadcastToKind.b1to4,
				(byte)BroadcastToKind.b1to8,
				(byte)BroadcastToKind.b1to4,
				(byte)BroadcastToKind.b1to16,
				(byte)BroadcastToKind.b1to16,
				(byte)BroadcastToKind.b1to8,
				(byte)BroadcastToKind.b1to8,
				(byte)BroadcastToKind.b1to8,
				(byte)BroadcastToKind.b1to16,
				(byte)BroadcastToKind.b1to8,
				(byte)BroadcastToKind.b1to4,
				(byte)BroadcastToKind.b1to8,
				(byte)BroadcastToKind.b1to16,
				(byte)BroadcastToKind.b1to2,
				(byte)BroadcastToKind.b1to4,
				(byte)BroadcastToKind.b1to8,
				(byte)BroadcastToKind.b1to2,
				(byte)BroadcastToKind.b1to4,
				(byte)BroadcastToKind.b1to8,
				(byte)BroadcastToKind.b1to4,
				(byte)BroadcastToKind.b1to8,
				(byte)BroadcastToKind.b1to16,
				// GENERATOR-END: BcstTo
			};
#if HAS_SPAN
			ReadOnlySpan<byte>
#else
			byte[]
#endif
			data = new byte[IcedConstants.NumberOfMemorySizes] {
				// GENERATOR-BEGIN: MemorySizes
				// ⚠️This was generated by GENERATOR!🦹‍♂️
				(byte)MemoryKeywords.None,
				(byte)MemoryKeywords.@byte,
				(byte)MemoryKeywords.word,
				(byte)MemoryKeywords.dword,
				(byte)MemoryKeywords.qword,
				(byte)MemoryKeywords.qword,
				(byte)MemoryKeywords.oword,
				(byte)MemoryKeywords.yword,
				(byte)MemoryKeywords.zword,
				(byte)MemoryKeywords.@byte,
				(byte)MemoryKeywords.word,
				(byte)MemoryKeywords.dword,
				(byte)MemoryKeywords.qword,
				(byte)MemoryKeywords.oword,
				(byte)MemoryKeywords.yword,
				(byte)MemoryKeywords.zword,
				(byte)MemoryKeywords.far,
				(byte)MemoryKeywords.far,
				(byte)MemoryKeywords.far,
				(byte)MemoryKeywords.word,
				(byte)MemoryKeywords.dword,
				(byte)MemoryKeywords.qword,
				(byte)MemoryKeywords.None,
				(byte)MemoryKeywords.None,
				(byte)MemoryKeywords.qword,
				(byte)MemoryKeywords.oword,
				(byte)MemoryKeywords.None,
				(byte)MemoryKeywords.None,
				(byte)MemoryKeywords.word,
				(byte)MemoryKeywords.dword,
				(byte)MemoryKeywords.qword,
				(byte)MemoryKeywords.tword,
				(byte)MemoryKeywords.oword,
				(byte)MemoryKeywords.word,
				(byte)MemoryKeywords.fpuenv14,
				(byte)MemoryKeywords.fpuenv28,
				(byte)MemoryKeywords.fpustate94,
				(byte)MemoryKeywords.fpustate108,
				(byte)MemoryKeywords.None,
				(byte)MemoryKeywords.None,
				(byte)MemoryKeywords.None,
				(byte)MemoryKeywords.None,
				(byte)MemoryKeywords.tword,
				(byte)MemoryKeywords.word,
				(byte)MemoryKeywords.word,
				(byte)MemoryKeywords.dword,
				(byte)MemoryKeywords.dword,
				(byte)MemoryKeywords.dword,
				(byte)MemoryKeywords.dword,
				(byte)MemoryKeywords.dword,
				(byte)MemoryKeywords.qword,
				(byte)MemoryKeywords.qword,
				(byte)MemoryKeywords.qword,
				(byte)MemoryKeywords.qword,
				(byte)MemoryKeywords.qword,
				(byte)MemoryKeywords.qword,
				(byte)MemoryKeywords.qword,
				(byte)MemoryKeywords.qword,
				(byte)MemoryKeywords.oword,
				(byte)MemoryKeywords.oword,
				(byte)MemoryKeywords.oword,
				(byte)MemoryKeywords.oword,
				(byte)MemoryKeywords.oword,
				(byte)MemoryKeywords.oword,
				(byte)MemoryKeywords.oword,
				(byte)MemoryKeywords.oword,
				(byte)MemoryKeywords.oword,
				(byte)MemoryKeywords.oword,
				(byte)MemoryKeywords.oword,
				(byte)MemoryKeywords.oword,
				(byte)MemoryKeywords.oword,
				(byte)MemoryKeywords.yword,
				(byte)MemoryKeywords.yword,
				(byte)MemoryKeywords.yword,
				(byte)MemoryKeywords.yword,
				(byte)MemoryKeywords.yword,
				(byte)MemoryKeywords.yword,
				(byte)MemoryKeywords.yword,
				(byte)MemoryKeywords.yword,
				(byte)MemoryKeywords.yword,
				(byte)MemoryKeywords.yword,
				(byte)MemoryKeywords.yword,
				(byte)MemoryKeywords.yword,
				(byte)MemoryKeywords.yword,
				(byte)MemoryKeywords.yword,
				(byte)MemoryKeywords.yword,
				(byte)MemoryKeywords.yword,
				(byte)MemoryKeywords.zword,
				(byte)MemoryKeywords.zword,
				(byte)MemoryKeywords.zword,
				(byte)MemoryKeywords.zword,
				(byte)MemoryKeywords.zword,
				(byte)MemoryKeywords.zword,
				(byte)MemoryKeywords.zword,
				(byte)MemoryKeywords.zword,
				(byte)MemoryKeywords.zword,
				(byte)MemoryKeywords.zword,
				(byte)MemoryKeywords.zword,
				(byte)MemoryKeywords.zword,
				(byte)MemoryKeywords.zword,
				(byte)MemoryKeywords.dword,
				(byte)MemoryKeywords.dword,
				(byte)MemoryKeywords.dword,
				(byte)MemoryKeywords.dword,
				(byte)MemoryKeywords.dword,
				(byte)MemoryKeywords.qword,
				(byte)MemoryKeywords.qword,
				(byte)MemoryKeywords.qword,
				(byte)MemoryKeywords.dword,
				(byte)MemoryKeywords.qword,
				(byte)MemoryKeywords.dword,
				(byte)MemoryKeywords.dword,
				(byte)MemoryKeywords.qword,
				(byte)MemoryKeywords.qword,
				(byte)MemoryKeywords.qword,
				(byte)MemoryKeywords.dword,
				(byte)MemoryKeywords.qword,
				(byte)MemoryKeywords.dword,
				(byte)MemoryKeywords.dword,
				(byte)MemoryKeywords.qword,
				(byte)MemoryKeywords.qword,
				(byte)MemoryKeywords.qword,
				(byte)MemoryKeywords.dword,
				(byte)MemoryKeywords.qword,
				(byte)MemoryKeywords.dword,
				(byte)MemoryKeywords.dword,
				(byte)MemoryKeywords.dword,
				(byte)MemoryKeywords.qword,
				(byte)MemoryKeywords.qword,
				(byte)MemoryKeywords.qword,
				(byte)MemoryKeywords.qword,
				(byte)MemoryKeywords.qword,
				(byte)MemoryKeywords.qword,
				(byte)MemoryKeywords.dword,
				(byte)MemoryKeywords.dword,
				(byte)MemoryKeywords.dword,
				// GENERATOR-END: MemorySizes
			};

			var infos = new Info[IcedConstants.NumberOfMemorySizes];
			var b1to2 = new FormatterString("1to2");
			var b1to4 = new FormatterString("1to4");
			var b1to8 = new FormatterString("1to8");
			var b1to16 = new FormatterString("1to16");
			var str_byte = new FormatterString("byte");
			var str_dword = new FormatterString("dword");
			var str_far = new FormatterString("far");
			var str_fpuenv14 = new FormatterString("fpuenv14");
			var str_fpuenv28 = new FormatterString("fpuenv28");
			var str_fpustate108 = new FormatterString("fpustate108");
			var str_fpustate94 = new FormatterString("fpustate94");
			var str_oword = new FormatterString("oword");
			var str_qword = new FormatterString("qword");
			var str_tword = new FormatterString("tword");
			var str_word = new FormatterString("word");
			var str_yword = new FormatterString("yword");
			var str_zword = new FormatterString("zword");
			for (int i = 0; i < infos.Length; i++) {
				var d = data[i];
				var keyword = ((MemoryKeywords)d) switch {
					MemoryKeywords.None => default,
					MemoryKeywords.@byte => str_byte,
					MemoryKeywords.dword => str_dword,
					MemoryKeywords.far => str_far,
					MemoryKeywords.fpuenv14 => str_fpuenv14,
					MemoryKeywords.fpuenv28 => str_fpuenv28,
					MemoryKeywords.fpustate108 => str_fpustate108,
					MemoryKeywords.fpustate94 => str_fpustate94,
					MemoryKeywords.oword => str_oword,
					MemoryKeywords.qword => str_qword,
					MemoryKeywords.tword => str_tword,
					MemoryKeywords.word => str_word,
					MemoryKeywords.yword => str_yword,
					MemoryKeywords.zword => str_zword,
					_ => throw new InvalidOperationException(),
				};
				FormatterString bcstTo;
				if (i < (int)IcedConstants.FirstBroadcastMemorySize)
					bcstTo = default;
				else {
					bcstTo = ((BroadcastToKind)bcstToData[i - (int)IcedConstants.FirstBroadcastMemorySize]) switch {
						BroadcastToKind.b1to2 => b1to2,
						BroadcastToKind.b1to4 => b1to4,
						BroadcastToKind.b1to8 => b1to8,
						BroadcastToKind.b1to16 => b1to16,
						_ => throw new InvalidOperationException(),
					};
				}

				infos[i] = new Info(keyword, bcstTo);
			}

			return infos;
		}
	}
}
#endif
